<?php 
//引进配置信息
include '../include/init.php';
//引入数据库配置信息
include '../include/mysql.config.php';
//引入公共函数
include '../include/common.fun.php';
islogin();



if ($_POST){
	$title=$_POST['title'];
	$author=$_POST['author'];
	$content=$_POST['content'];
	$address=$_POST['address'];
	$catId=$_POST['cid'];
	if ($title&&$author&&$content&&$address) {
		$date=array(
			'case_name' => $title,
			'case_addtime' => time(),
			'case_content' => $content,
			'case_author' => $author,
			'case_url'=>$address,
			'case_cat_id'=>$catId
		);
	}

	if ($_FILES) {
		$res=upload('img1','../uploads/case');
		if($res['error']==1){
			alert($res['msg']);exit;
		}elseif ($res['error']==2) {
			$date['case_img']=$res['path'];
			$thumb_img=thumb('../uploads/case/'.$res['path'],'../uploads/case_thumb',250,250);
			$date['case_img_thumb']=$thumb_img['path'];
		}
	}
	$result=$db->insert('wd_case',$date);
	if ($result) {
		alert('添加成功','case_list.php');exit;
	}else{
		alert('添加失败');exit;
	}
}

$sql="SELECT * from wd_case_cat";
$cat=$db->getAll($sql);

include 'view/case_add.php';